home *** CD-ROM | disk | FTP | other *** search
/ Disc to the Future 2 / Disc to the Future Part II Programmer's Reference (Wayzata Technology)(6013)(1992).bin / MAC / THINKC / 1_0-2 / D2R_FOLD / D2R_DELE.C < prev    next >
C/C++ Source or Header  |  1986-11-08  |  2KB  |  64 lines

  1. #include "::MacIncludes:DeviceMgr.h"
  2. #include "::MacIncludes:EventMgr.h"
  3. #include "::MacIncludes:FontMgr.h"
  4. #include "::MacIncludes:WindowMgr.h"
  5. #include "::MacIncludes:DialogMgr.h"
  6. #include "::MacIncludes:ControlMgr.h"
  7. #include "::MacIncludes:MenuMgr.h"
  8. #include "::MacIncludes:MemoryMgr.h"
  9. #include "::MacIncludes:StdFilePkg.h"
  10. #include "::MacIncludes:SegmentLdr.h"
  11.  
  12. #define NULL 0L
  13.  
  14. int firstTime = TRUE;
  15.  
  16. pascal int mydlgHook(theItem, theDialog) /* dlgHook to make 'Delete' button */
  17. int        theItem;
  18. DialogPtr    theDialog;
  19. {
  20.     int                theType;
  21.     Handle            theItemH;
  22.     Rect            theBox;
  23.     static    Str255    OPEN="\pDelete";
  24.     ControlHandle    whichControl;
  25.     
  26.     if (firstTime) /* Not very elegant */
  27.     {
  28.         GetDItem(theDialog, getOpen, &theType, &theItemH, &theBox);
  29.         SetCTitle(theItemH, OPEN);
  30.         SetDItem(theDialog, getOpen, theType, theItemH, &theBox);
  31.         firstTime = FALSE;
  32.     }
  33.     return( theItem );
  34. }
  35.  
  36.  
  37.  
  38. deletefile() /* Puts up Standard File dialog and allows you to delete a file */
  39. {
  40.     SFReply        reply;
  41.     Point         pt;
  42.     char        volname[30];
  43.     int            tint,
  44.                 errCode,
  45.                 result;
  46.     long        tlong;
  47.     
  48.     InitCursor();
  49.     SetPt(&pt, (512-348)/2, (342-200)/2);
  50.     firstTime = TRUE;
  51.     SFGetFile(pt, "\p", NULL, -1, NULL, &mydlgHook, &reply);
  52.     if (reply.good)
  53.     {
  54.         GetVInfo(reply.vRefNum, volname, &tint, &tlong);
  55.         if (PromptAlert("\pAre you sure you want to delete '",reply.fName,"\p' ?",NULL))
  56.         {
  57.             errCode = FSDelete(reply.fName,reply.vRefNum); /* Bye, Bye file!! */
  58.             if (errCode != noErr)
  59.                 ErrorAlert("\pSorry - can't delete that file!");
  60.             FlushVol(NULL,reply.vRefNum); /* Must do this */
  61.         }
  62.     }
  63. }
  64.